#endcoding:utf-8
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

@deal=(demandid,offerid,url,obj) ->
  if confirm "您确定吗？"
    $.ajax url,
      type: 'POST'
      data: {deal:{demand_id:demandid,offer_id:offerid}}
      dataType: 'json'
      success: (data, textStatus, jqXHR) ->
        $("#offer-"+offerid).parent().html '<img src="/assets/bit50.png">'
        $(".dealbtn").remove()
        $(".status").find('img').attr('src','/assets/status2.png')

@takeOrder = (oid,obj,demand_user_id,demand_id)->
  if confirm "确定接下这个订单吗？"
    $.ajax "/takeOrder?id="+oid,
      type: 'POST'
      data: {offer:{status:2,demand_user_id:demand_user_id,demand_id:demand_id}}
      dataTyp: 'json'
      success:(data,textStatus,jqXHR)->
        $(obj).attr({onclick:"return false",class:"btn btn-default"}).html("已接单")
        $(".status").find('img').attr('src','/assets/status3.png')

@finish = (obj,did)->
  if confirm "确定完成了吗？"
    $.ajax "/finishDemand?id="+did,
      type: 'POST'
      data: {demand:{status:4}}
      dataTyp: 'json'
      success:(data,textStatus,jqXHR)->
        $(obj).attr({onclick:"return false",class:"btn btn-default"}).html("已完成")
        $(".status").find('img').attr('src','/assets/status4.png')